class Node(object):
    # 初始化
    def __init__(self,data=None):
        self.data = data
        self.next = None
        self.prev = None

class List(object):
    def __init__(self, max_length):
        self.max_length = max_length
        self.head = Node()
        self.tail = Node()
        self.length = 0

        self.head.next = self.tail
        self.tail.prev = self.head

    def unshift(self, data):
        assert not self.full()

        newNode = Node()
        newNode.data = data
        pnode = self.tail.prev
        pnode.next = newNode
        newNode.prev = pnode
        self.tail.prev = newNode
        newNode.next = self.tail
        self.length += 1

    def shift(self):
        assert not self.empty()

        node = self.head.next
        nnode = node.next
        self.head.next = nnode
        nnode.prev = self.head
        self.length -= 1

        return node.data

    def full(self):
        return self.length == self.max_length

    def empty(self):
        return self.length == 0

    def __iter__(self):
        node = self.head.next
        while node != self.tail:
            yield node.data
            node = node.next

    def __len__(self):
        return self.length


if __name__ == '__main__':
    l = List(5)

    for i in range(5, 10):
        l.unshift(i)

    for i in l:
        print(i)

    # l.unshift(10)

    m = l.shift()
    print(m)
    l.unshift(100)

    for i in l:
        print(i)